package com.wx.controller;

import com.alibaba.fastjson.JSONObject;
import com.wx.model.*;
import com.wx.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/page")
public class pageController {

//    -------------------------------------------------前台公司信息模块--------------------------------------------------
    @Autowired
    ICompanyService iCompanyService;
    @RequestMapping("/companyFindAll")
    public JSONObject findAll(){
        CompanyModel list=iCompanyService.findAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }

    //    --------------------------------------------前台工程类型模块--------------------------------------------------
    @Autowired
    IProductService iProductService;
    @RequestMapping("/productFindAll")
    public JSONObject productFindAll(){
        List<ProductModel> list=iProductService.productFindAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }

    @RequestMapping("/casetypeFindAll")
    public JSONObject casetypeFindAll(){
        List<CaseTypeModel> list=iProductService.casetypeFindAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }



//----------------------------------------------------前台工程案例模块-----------------------------------------------
    @Autowired
    IProductsService iProductsService;
    @RequestMapping("/producatspageFindAll")
    public JSONObject producatspageFindAll(){
        List<ProductModel> list=iProductsService.producatspageFindAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }

    @PostMapping("/producatsPage")
    public JSONObject producatsPage(@RequestBody ProductModel productModel){
        productModel.setCasetypeid(productModel.getCasetypeid()==null || "".equals(productModel.getCasetypeid()) ? 0 : (productModel.getCasetypeid()));
        productModel.setPage(productModel.getPage()==null || "".equals(productModel.getPage()) ? 1 :(productModel.getPage()));
        List<ProductModel> list=iProductsService.producatsPage(productModel);
        int number=iProductsService.getcount(productModel);
        int pa=productModel.getPage();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        jsonObject.put("number",number);
        jsonObject.put("pa",pa);
        return jsonObject;
    }

    @RequestMapping("/producatsFindById")
    public JSONObject producatsFindById(@RequestBody ProductModel productModel) {
        ProductModel productModel1 = iProductsService.producatsFindById(productModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("productModel", productModel1);
        return jsonObject;
    }


    //----------------------------------------------------前台新闻模块---------------------------------------------------
    @Autowired
    INews iNews;
    @RequestMapping("/newsPageFind")
    public JSONObject newsPageFind(@RequestBody NewsModel newsModel){
        newsModel.setPage(newsModel.getPage() == null || "".equals(newsModel.getPage()) ? 1:(newsModel.getPage()));
        List<NewsModel> list=iNews.newsPageFind(newsModel);
        int number=iNews.getCont(newsModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        jsonObject.put("number",number);
        return jsonObject;
    }

    @RequestMapping("/newsFindById")
    public JSONObject newsFindById(@RequestBody NewsModel newsModel){
        NewsModel newsModel1=iNews.newsFindById(newsModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("newsModel",newsModel1);
        return jsonObject;
    }

    @RequestMapping("/newsTypeFindAll")
    public JSONObject newsTypeFindAll(){
        List<NewsModel> newsModel1=iNews.newsTypeFindAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("newsModel",newsModel1);
        return jsonObject;
    }


    //----------------------------------------------------导航模块-------------------------------------------------------
    @Autowired
    INavigationService iNavigationService;
    @GetMapping("/NavigationPageFindAll")
    public JSONObject NavigationPageFindAll(){
        List<NavigationModel> list=iNavigationService.findAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }


    //----------------------------------------------------招聘模块-------------------------------------------------------
    @Autowired
    IRecruitmentService iRecruitmentService;
    @RequestMapping("/FindAll")
    public JSONObject FindAll(){
        List<RecruitmentModel> list=iRecruitmentService.findAll();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }

    //----------------------------------------------------在线留言-------------------------------------------------------
    @Autowired
    IMessageService IMessageService;
    @RequestMapping("/messageAdd")
    public JSONObject messageAdd(@RequestBody MessageModel messageModel){
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String data=sdf.format(d);
        messageModel.setDate(data);
        int count= IMessageService.messageAdd(messageModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("count",count);
        return jsonObject;
    }
}
